package demo;

import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaRDD;
import org.apache.spark.api.java.JavaSparkContext;
import org.apache.spark.api.java.function.Function;

import java.util.List;

public class SparkMapDemo {
    public static void main(String[] args) {

        SparkConf sparkConf = new SparkConf().setAppName("SparkTextFile").setMaster("local");
        JavaSparkContext javaSparkContext = new JavaSparkContext(sparkConf);
        JavaRDD<String> rdd = javaSparkContext.textFile("H:\\yjy\\资源\\新建文件夹\\num.txt");

        // map: 参数是Function<T1, R>类型对象,T1是RDD元素的数据类型, R是转换之后新的RDD的元素的数据类型
        JavaRDD<Integer> map = rdd.map(new Function<String, Integer>() {
            @Override
            public Integer call(String s) throws Exception {
                return Integer.parseInt(s)+10;
            }
        });
//        map.collect();
        List<Integer> res = map.collect();
        for (Integer s:res){
            System.out.println(s);
        }
    }
}
